package com.xhu.rjsx2.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xhu.rjsx2.pojo.Member;
import com.xhu.rjsx2.pojo.vo.MemberVO;
import com.xhu.rjsx2.pojo.vo.PageVO;
import com.xhu.rjsx2.service.MemberService;
import com.xhu.rjsx2.mapper.MemberMapper;
import com.xhu.rjsx2.util.BeanCopyUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author ZQ
* @description 针对表【member】的数据库操作Service实现
* @createDate 2023-05-08 21:02:40
*/
@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member>
    implements MemberService{


    @Override
    public PageVO listAllMemberPage(Integer pageNum, Integer pageSize, String memberName, String memberPhone, Date memberStartTime, Date memberEndTime) {
        LambdaQueryWrapper<Member> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(!StrUtil.isBlankIfStr(memberName),Member::getMemberName,memberName)
                .like(!StrUtil.isBlankIfStr(memberPhone),Member::getMemberPhone,memberPhone)
                .ge(!StrUtil.isBlankIfStr(memberStartTime),Member::getMemberStartTime,memberStartTime)
                .le(!StrUtil.isBlankIfStr(memberEndTime),Member::getMemberEndTime,memberEndTime);
        Page<Member> page = new Page<>(pageNum,pageSize);
        page(page,queryWrapper);
        List<MemberVO> memberVOList = BeanCopyUtils.copyBeanList(page.getRecords(), MemberVO.class);
        return new PageVO(memberVOList, page.getTotal());

    }


}




